function generateAsync(msg) {
  return function () {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        console.log(msg);
        resolve(msg)
      }, 1000)
    })  
  }
}
var list = []
for (let i = 0; i < 10; i++) {
  list.push(generateAsync(i))
}

let result = [];
function loop (list, result, cb) {
  let current = list.shift();
  if (list.length) {
    current().then(res => {
      result.push(res);
      loop(list, result, cb)
    })
  } else {
    current().then(res => {
      result.push(res);
      cb(result)
    })
  }
}
loop(list, result, function (res) {
  console.log(res);
})